Open
Conversation
KimGyeong
commented
Apr 28, 2021
Comment on lines
+2
to
+8
| public static void main(String[] args){ | ||
| calculate(); | ||
| } | ||
| public static void calculate(){ | ||
| StringCalculator stringCalculator = new StringCalculator(); | ||
| Output.printOutput(stringCalculator.calculateStr(Input.splitInput())); | ||
| } |
|
|
||
| public class StringCalculator { | ||
|
|
||
| public int calculateStr(String[] inputSplit){ |
Author
There was a problem hiding this comment.
메소드 네임에는 타입이 들어가는 것을 추천드리지 않아요. 간단하게 calculate로 바꿔도 괜찮을 것 같습니다.
Comment on lines
+39
to
+41
| } catch(ArithmeticException e){ | ||
| System.out.println("0 으로 나눌수 없음 : " + num1 + "/" + num2); | ||
| } |
| return splitString; | ||
| } | ||
|
|
||
| public static void checkInput(String[] splitInput){ |
Author
There was a problem hiding this comment.
한 클래스 내에서만 사용하는 메소드는 접근제어자를 private으로 변경해주세요.
또한 연산 입력의 오류의 케이스가 더 있을 것 같은데 한번 생각해보면 좋을 것 같아요.
Comment on lines
+13
to
+36
| public int calculate(int firstFactor, char operator, int secondFactor) { | ||
| if (operator == '+') | ||
| return add(firstFactor,secondFactor); | ||
| if (operator == '-') | ||
| return subtract(firstFactor,secondFactor); | ||
| if (operator == '*') | ||
| return multiply(firstFactor,secondFactor); | ||
| if (operator == '/') | ||
| return divide(firstFactor,secondFactor); | ||
|
|
||
| throw new RuntimeException("올바르지 않은 연산자"); | ||
| } | ||
|
|
||
|
|
||
| public int add(int num1, int num2){ | ||
| return num1 + num2; | ||
| } | ||
| public int subtract(int num1, int num2){ | ||
| return num1 - num2; | ||
| } | ||
| public int multiply(int num1, int num2){ | ||
| return num1 * num2; | ||
| } | ||
| public int divide(int num1, int num2){ |
| } catch(ArithmeticException e){ | ||
| System.out.println("0 으로 나눌수 없음 : " + num1 + "/" + num2); | ||
| } | ||
| throw new RuntimeException(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.